package com.linkage.jz.bankruptcy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.bean.TalkPerson;

import java.util.List;

/**
 * Created by 16838 on 2018/5/22.
 */
public class LvAdapter extends BaseAdapter{
    private Context context;
    private List<TalkPerson>list;
    private Check check;
   public LvAdapter(Context context,List<TalkPerson>list){
       this.context=context;
       this.list=list;
   }
    public void setCheck(Check check){
        this.check=check;
    }
    public interface Check{
        public  void mycheck(int position, boolean isChecked);

    }



    @Override
    public int getCount() {
        return list.size();
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder;
        if(convertView==null) {
            viewHoder=new ViewHoder();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_layout,null);
            viewHoder.checkBox=(CheckBox)convertView.findViewById(R.id.checkBox);
            convertView.setTag(viewHoder);
        }else{
            viewHoder= (ViewHoder) convertView.getTag();
        }
//        viewHoder.checkBox.setText(list.get(position).content);
        viewHoder.checkBox.setChecked(list.get(position).isSelected());
        viewHoder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(check!=null) {
                    check.mycheck(position,isChecked);
                }
            }
        });

        return convertView;
    }

    class ViewHoder{
        CheckBox checkBox;
    }




    @Override
    public Object getItem(int position) {
        return null;
    }
    @Override
    public long getItemId(int position) {
        return 0;
    }

}
